<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    request.setAttribute("basePath",basePath);
%>
<!DOCTYPE>
<html>
<head>
    <title>明细信息</title>
    <%@ include file="/resources/js/easyui/taglibs.jsp"%>
    <%@ include file="/resources/js/easyui/_easyui.jsp"%>
    <%@ include file="/resources/js/easyui/_message.jsp"%>
    <%@ include file="/resources/js/easyui/_viewJS.jsp"%>
</head>

<body class="easyui-layout">
    <form id="addform">
        <table class="tableForm" style="width: 100%;">
            <tr>
                <th align="right" valign="top"><span class="redStart">*</span><label>套餐名称：</label></th>
                <td>
                    <input class="easyui-validatebox easyui-textbox" name="discountname" style="width:200px" data-options="required:true" />
                </td>
            </tr>

            <tr>
                <th align="right" valign="top"><span class="redStart">*</span><label>金额：</label></th>
                <td>
                    <input class="easyui-validatebox easyui-textbox" name="money" style="width:200px" data-options="required:true,validType:'PositiveInteger'" />
                </td>
            </tr>

            <tr>
                <th align="right" valign="top"><span class="redStart">*</span><label>设备余币：</label></th>
                <td>
                    <input class="easyui-validatebox easyui-textbox" name="coin" style="width:200px" data-options="required:true,validType:'PositiveInteger'" />
                </td>
            </tr>
        </table>
    </form>

<script type="application/javascript">
    function add(){
        if($("#addform").form('validate')){
            $.ajax({
                url:'${basePath}web/discount/add',
                type : 'POST',
                data : $("#addform").serialize(),
                async : false,
                traditional:true,
                error: function (response) {
                    ViewHelper.func.ajaxErrorMessage(response);
                },
                success: function (ret) {
                    if(ret.result) {
                        $.messager.alert('提示信息！',ret.info,'info');
                        parent.view.closeAddWin(1);
                        $("#addform").form('clear');
                    }else{
                        $.messager.alert('提示','保存失败!','error');
                    }
                }
            });
        }
    }

    $.extend($.fn.validatebox.defaults.rules, {
        PositiveInteger: {
            validator: function (value) {
                var re = new RegExp(/^\d+$/);
                if (value.match(re) != null) {
                    return true;
                }
                return false;
            },
            message: '正整数输入不合法'
        }
    });

</script>
</body>
</html>
